package ljt.music.utils;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.os.Looper;
import android.view.View;

/**
 *
 * @author jiangtao
 * @date 2017/10/14
 */

public class StatusBarUtils {
    private static void setStatusBarDark(Activity activity, boolean darkmode) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (darkmode) {
                activity.getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
            } else {
                activity.getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
                activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
            }
        }
    }

    public static void setStatusBarDarkInUiThread(final Activity activity, final boolean darkmode) {
        if (Looper.getMainLooper() == Looper.myLooper()) {
            setStatusBarDark(activity, darkmode);
        } else {
            activity.runOnUiThread(() -> setStatusBarDark(activity, darkmode));
        }
    }
}
